package controller

import (
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"morleyStoneHome/model"
	"morleyStoneHome/result"
	"morleyStoneHome/service"
)

type StoController struct{}

func NewStoController() *StoController {
	return &StoController{}
}

//签名接口
func (c *StoController) SignData(ctx *gin.Context) {
	//addr := ctx.PostForm("addr") //地址
	var cat model.Catcoin
	ctx.BindJSON(&cat)
	addr := cat.Addr
	logrus.Info("sto controller.SignData :: addr = ", addr)
	resultRes := result.NewResult(ctx)
	if "" == addr {
		resultRes.Error(1, "参数为空")
		return
	}
	signData, msg, err3 := service.StoService.SignData(addr)
	if nil != err3 {
		resultRes.Error(1, msg)
		return
	}
	if nil == signData { //余额为0的情况下，接口请求是正常的：0，但无数据，返回提示信息。
		resultRes.Error(0, msg)
		return
	}
	resultRes.Success(signData)
}

//冻结接口
func (c *StoController) Freeze(ctx *gin.Context) {
	//addr := ctx.PostForm("addr") //地址
	var cat model.Catcoin
	ctx.BindJSON(&cat)
	addr := cat.Addr
	logrus.Info("controller.Freeze :: ", addr)
	err := service.StoService.Freeze(addr)
	resultRes := result.NewResult(ctx)
	if nil != err {
		resultRes.Error(1, err.Error())
	}
	resultRes.Success("success")
}
